﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Laugh.Data
{
    public interface IRepository<T> : IDisposable where T : IEntity
    {
        ITransaction BeginTransaction();

        #region 切换数据库
        IRepository<T> UseDatabase(string key);
        #endregion

        #region 增加、删除、修改
        void Delete(T entity);
        void DeleteAll();
        void DeleteBy(int id);
        void DeleteById(object id);
        T Update(T entity);
        T SaveOrUpdate(T entity);
        T Save(T entity);
        void Detach(T entity);
        void Attach(T entity);
        void Refresh(T entity);
        void Copy(T source, T target);
        void Evict(T entity);
        void Initialize(object obj);
        #endregion

        #region 查询
        T Get(object id);
        void Load(T newObj, object id);
        T Get(Expression<Func<T, bool>> predicate);
        int Count();
        int Count(Expression<Func<T, bool>> predicate);
        bool Exists();
        bool Exists(Expression<Func<T, bool>> predicate);
        IQueryable<T> All { get; }
        IQueryable<T> Fetch(Expression<Func<T, bool>> predicate);
        #endregion
    }
}
